<?php
       class home extends template{
           function __construct($db,$info)
           { 
             $this->db=$db;   
             $this->info=$info;
             $this->db->get_connect();
           }
           
           function view(){ 
           //   global $db_exec;
               
             $this->db->get_connect();
             $this->setdb($this->db);
             $oauth="";
            
             $oauth=$_COOKIE['oauth'];
       
             
             if($_GET['nouser']&&$this->checkadmin()===false)
             {
             $oauth2=$_COOKIE['oauth'];
            // echo $oauth2;
//             exit;
             
             }
             
             if($_GET['tagid'])
             {
             $tagid=$_GET['tagid'];
             
             }
             if($_GET['searchText'])
             {
             $searchText=$_GET['searchText'];
             
             }
             $array['userdata']=$this->getuserbyoauth($_COOKIE['oauth']);

             if($_GET['orderby'])
             {
             switch (intval($_GET['orderby'])) {
                case 1:
                    $setorder="tb_book.date desc,tb_book.time desc";
                    break;
                case 2:
                    $setorder="tb_book.date asc,tb_book.time asc";
                    break;
                case 3:
                    $setorder="tb_book.title asc";
                    break;
                case 5:
                    $setorder="date desc,TIMESTAMP(date,time) asc";
                    break;
                default:
                    $setorder="tb_book.createdate desc";
                    break;

            }
             $orderby=" order by ".$setorder;
             
             }else
             {
             $orderby=" order by tb_book.date desc,tb_book.time desc";
             }
             
             
             
             
             //echo "<pre>";
//             print_r($_SERVER['QUERY_STRING']);
//             echo "</pre>;";
             //$query1=$_SERVER['QUERY_STRING'];
             //parse_str($query1);
             $queryarr=array();
             $query1="";
             if(count($_GET))
             {
             foreach($_GET as $keyget => $valueget)
             {
             
             if($keyget!="orderby")
             {
             $queryarr[]=$keyget.'='.$valueget;
             
             }
             
             }
             
             }
             if(count($queryarr))
             {
             $query1=join("&",$queryarr);
             
             }
             
             $data['query1']=$query1;
            // exit;
            if($oauth)
            {
             $data['arraybook']=$this->getallbook($array['userdata']['shelfid'],$oauth,$tagid,$searchText,$oauth2,$orderby);
            }
             $this->db->closedb(); 
             

             $this->setdata($data);
             $this->load('main');
             
           
           }
        
        
        }
?>
